# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime

from django.db import models
from django.contrib.auth.models import AbstractUser  # django_model User

# Create your models here.


class UserProfile(AbstractUser):
	"""继承AbstractUser，扩展用户信息，覆盖默认User"""
	nickname = models.CharField(verbose_name=u'昵称', max_length=55, default='')
	birthday = models.DateField(verbose_name=u'生日', null=True, blank=True)
	gender = models.CharField(verbose_name=u'性别', choices=(('male', u'男'), ('female', u'女')), max_length=6)
	address = models.CharField(verbose_name=u'地址', max_length=100, default='')
	mobile = models.CharField(verbose_name=u'手机号', max_length=11, null=True, blank=True)
	image = models.ImageField(verbose_name=u'头像', upload_to='static/media/users/image_UserProfile/%Y/%m', default='static/media/users/default_UserProfile.png', max_length=100)

	class Meta:
		verbose_name = u'用户信息'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.username


class EmailVerifyRecord(models.Model):
	code = models.CharField(verbose_name=u'验证码', max_length=20)
	email = models.EmailField(verbose_name=u'邮箱', max_length=50)
	send_type = models.CharField(verbose_name=u'发送类型', choices=(('register', u'注册'), ('forget', u'找回密码')), max_length=10)
	send_time = models.DateTimeField(verbose_name=u'发送时间', default=datetime.datetime.now)
	expire_status = models.IntegerField(verbose_name=u'过期状态', choices=(('0', u'expired'), ('1', u'valid')), default=1)
	# 注意不是`datetime.datetime.now()`没有括号，若有括号则根据model编译的时间创建，若没有括号则根据实例化的时间创建

	class Meta:
		verbose_name = u'邮箱验证码'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return '{0}({1})'.format(self.code, self.email)


class Banner(models.Model):
	status = models.IntegerField(verbose_name=u'状态', choices=((0, u'下线'), (1, u'上线')), default=0)
	title = models.CharField(verbose_name=u'标题', max_length=100)
	image = models.ImageField(verbose_name=u'轮播图', upload_to='static/media/users/image_Banner/%Y/%m', max_length=100)
	href = models.URLField(verbose_name=u'访问地址', max_length=200)
	index = models.IntegerField(verbose_name=u'顺序', default=0)
	create_time = models.DateTimeField(verbose_name=u'创建时间', default=datetime.datetime.now)
	updata_time = models.DateTimeField(verbose_name=u'更新时间', auto_now=True)

	class Meta:
		verbose_name = u'轮播图'
		verbose_name_plural = verbose_name

	def __unicode__(self):
		return self.title
